package com.pickgliss.bitmapEngin.sound
{
	import com.pickgliss.utils.ObjectUtils;
	
	import flash.utils.Dictionary;
	
	public class AnimationSoundMgr
	{
		public function AnimationSoundMgr()
		{
			_sounds = new Dictionary();
		}
		
		private var _sounds:Dictionary;
		public function setup(xml:XML):void
		{
			var list:XMLList = xml..ASound;
			for(var i:int = 0;i<list.length();i++)
			{
				var aSound:AnimationSound = new AnimationSound();
				ObjectUtils.copyPorpertiesByXML(aSound,list[i]);
				_sounds[aSound.id] = aSound;
			}
		}
		
		public function play(clipid:String,soundID:String):void
		{
			var aSound:AnimationSound = _sounds[soundID];
			if(aSound)aSound.play(clipid);
		}
		
		public function stop(clipid:String,soundID:String):void
		{
			var aSound:AnimationSound = _sounds[soundID];
			if(aSound)aSound.stop(clipid);
		}
		
		private static var _instance:AnimationSoundMgr;
		public static function get Instance():AnimationSoundMgr
		{
			if(_instance == null)
			{
				_instance = new AnimationSoundMgr();
			}
			return _instance;
		}
		
		public function stopClipSound(clipid:String):void
		{
			for each (var element:AnimationSound in _sounds)
			{
				if(element)element.stop(clipid);
			}
		}
	}
}